﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using DAL;

namespace PeisongWeb
{
    public partial class buyer_Permission : buyerPage
    {
        protected int cusId
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["cusId"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["cusId"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("EB", 1))
                {
                    if (Request.QueryString["customer"] != null)
                    {
                        if (Library.Number.IsIntPositive(Request.QueryString["customer"]))
                        {
                            cusId = Convert.ToInt32(Request.QueryString["customer"]);
                        }
                    }
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "buyer_index.html");
                    return;
                }
            }
        }
        
        private void rptBind()
        {

            DataTable dt = DbHelper.ExecuteDataTable("p_BuyerPermission_list", cusId);
            if (dt.Rows.Count > 0)
            {
                rpt_list.DataSource = dt;
                rpt_list.DataBind();
            }
            else
            {
                Library.Script.ClientMsgUrl("无效的用户", "adminList.aspx");
                return;

            }

            lbl_CustomerName.Text = logic.customer.getById(cusId).Username;
            


        }

        protected void bt_save_Click(object sender, EventArgs e)
        {
            logic.customer.updatePermission(cusId, hid_Popedom.Value);
            Library.Script.ClientMsgUrl("权限设置成功!", "buyer_customerList.html");
        }
    }
}
